//
//  SearchListViewController.m
//  SafeFoodManagerDemo
//
//  Created by bob on 2017/10/17.
//  Copyright © 2017年 bob. All rights reserved.
//

#import "SearchListViewController.h"
#import "TotalListNumView.h"
#import "SearchBtnView.h"
#import "BatchConversionHeader.h"
@interface SearchListViewController ()

@property(nonatomic,strong)SearchBtnView *SearchBar;

@property(nonatomic,strong)UIButton *AddBtn;

@property(nonatomic,strong)TotalListNumView *TotalNumView;


@end

@implementation SearchListViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [USER_DEFAULT setObject:@[] forKey:@"TBChoose"];//默认滞空
    
     [USER_DEFAULT setObject:@[] forKey:@"TBReqChoose"];//默认滞空
    
      if (!self.ishidenSearch) {
          //显示搜索
          [self.view addSubview:self.SearchBar];
          
      }
    [self.view addSubview:self.homeTableView];
    
    if (self.isEdit) {
        
        [self CreatAddBtn];//新增按钮
       
    
    }
    if (self.isdeleMore) {
        
        [self addEditBtn];
    }
    // Do any additional setup after loading the view.
  
}


-(void)    addEditBtn
{
   self.btn = [UIButton buttonWithType:UIButtonTypeSystem];
     self.btn.frame = CGRectMake(0, 0, 60, 20);
    
    [self.btn setTitle:@"编辑" forState:UIControlStateNormal];
    
    [self.btn setTitle:@"完成" forState:UIControlStateSelected];
    
      self.btn.titleLabel.font = [UIFont systemFontOfSize:15];
    
    [self.btn sizeToFit];
    
     self.btn.tintColor=[UIColor clearColor];
    
    [self.btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [self.btn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];

    UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithCustomView:self.btn];
   
    self.navigationItem.rightBarButtonItem=item;
    
    [self.btn addTarget:self action:@selector(GotoEdit:) forControlEvents:UIControlEventTouchUpInside];
   // self.btn.backgroundColor = [UIColor redColor];
}

-(void)setDeleStatue:(BOOL)deleStatue
{
    _deleStatue=deleStatue;
    
    if (deleStatue) {
        
        self.AddBtn.hidden=YES;
        
        self.DeleView.SeletAllBtn.selected=NO;
        
        self.DeleView.hidden=NO;
        
        [self.view addSubview:self.DeleView];
        
    }else{
        
        self.AddBtn.hidden=NO;
        
        self.DeleView.hidden=YES;
      

    }
    
}

-(DelectView*)DeleView
{
    if (!_DeleView) {
        
        CGRect frame;
        
        if (kDevice_Is_iPhoneX) {
           
            frame=CGRectMake(0, SCREEN_HEIGHT-45*SCREEN_WIDTH/320-64-IPhoneXTableHeight, SCREEN_WIDTH, 45*SCREEN_WIDTH/320);
            
        }else{
           
            frame=CGRectMake(0, SCREEN_HEIGHT-45*SCREEN_WIDTH/320-64, SCREEN_WIDTH, 45*SCREEN_WIDTH/320);
            
        }
        
        _DeleView=[[DelectView alloc]initWithFrame:frame];
            TBWeak;
        
        _DeleView.block=^(NSInteger type)
        {
            if (type==1) {
                //全选
                [weakSelf SeletAll];
                
            }else if (type==2)
            {
               //取消全选
                
                [weakSelf CanseletAll];
                
            }else{
                
                //删除
                [weakSelf DelectAll];
            }
            
        };
        
    }
    
    _DeleView.backgroundColor = [UIColor orangeColor];
    return _DeleView;
}

-(void)SeletAll
{
    
}//全选

-(void)CanseletAll{
    
    
}//取消全选

-(void)DelectAll{
    
    
}//全部删除

-(NSMutableArray*)dataArr
{
    if (!_dataArr) {
        
        _dataArr=[NSMutableArray array];
    }
    
    return _dataArr;
}


-(SearchBtnView*)SearchBar
{
    
    if (!_SearchBar) {
        
        _SearchBar=[[SearchBtnView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
        
        _SearchBar.placeHol=[NSString stringWithFormat:@"  %@",self.searchName];
        TBWeak;
        _SearchBar.block=^()
        {
            
            [weakSelf PushChangeStatueVC];
            
        };

    }
    
    return _SearchBar;
}


-(TotalListNumView*)TotalNumView
{
    if (!_TotalNumView) {
        
        _TotalNumView=[[TotalListNumView alloc]initWithFrame:CGRectMake(0, 0, self.homeTableView.frame.size.width, 40)];

    }
    
    
    return _TotalNumView;
}

-(TB_TableView*)homeTableView
{
    if (!_homeTableView) {
     
        CGFloat tabviewHeight;
        
        CGFloat tabley;
        
          if (!self.ishidenSearch) {
              
               if (kDevice_Is_iPhoneX) {
              
                    tabviewHeight=self.isEdit==NO?SCREEN_HEIGHT-64-50-IPhoneXTableHeight:SCREEN_HEIGHT-64-45*SCREEN_WIDTH/320.0-50-IPhoneXTableHeight;
                   
               }else{
              tabviewHeight=self.isEdit==NO?SCREEN_HEIGHT-64-50:SCREEN_HEIGHT-64-45*SCREEN_WIDTH/320.0-50;
               }
              tabley=50;
              
          }else{
              
              if (kDevice_Is_iPhoneX) {
                  
                   tabviewHeight=self.isEdit==NO?SCREEN_HEIGHT-64-IPhoneXTableHeight:SCREEN_HEIGHT-64-45*SCREEN_WIDTH/320.0-IPhoneXTableHeight;
                  
              }else{
              
              tabviewHeight=self.isEdit==NO?SCREEN_HEIGHT-64:SCREEN_HEIGHT-64-45*SCREEN_WIDTH/320.0;
              }
              tabley=0;
          }
        
        if (self.isGroupStyle) {
            
              _homeTableView=[[TB_TableView alloc]initWithFrame:CGRectMake(0, tabley, SCREEN_WIDTH, tabviewHeight) style:UITableViewStyleGrouped];
        }else{
            
            
              _homeTableView=[[TB_TableView alloc]initWithFrame:CGRectMake(0, tabley, SCREEN_WIDTH, tabviewHeight) style:UITableViewStylePlain];
        }
        
      
        
        _homeTableView.delegate=self;
        
        _homeTableView.dataSource=self;
   
      _homeTableView.tableHeaderView=self.TotalNumView;
   
        [self configScrollViewHeaderRefresh:_homeTableView autoRefresh:NO];//下拉刷新
        
        [self configScrollViewFooterLoadMore:_homeTableView];//加载更多
        
         [self configureNeedShowEmptyDataSetScrollView:self.homeTableView];//空白页配置
        
        _homeTableView.tableFooterView=[[UIView alloc]init];
        
    }
    return _homeTableView;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return self.dataArr.count;
    
}

-(void)setTotalNum:(NSString*)TotalNum
{
    _TotalNum=TotalNum;
    
    self.TotalNumView.ShowTip=TotalNum;
}

#pragma mark- 搜索跳转事件
-(void)PushChangeStatueVC
{
    
    
    
}

#pragma mark-编辑事件

-(void)GotoEdit:(UIButton*)sender
{
    
    
    
}

- (void)backBtnClicked
{
    
}
-(void)CreatAddBtn
{
    
    
    self.AddBtn=[UIButton buttonWithType:UIButtonTypeCustom];
   
    if (kDevice_Is_iPhoneX) {
        
          self.AddBtn.frame=CGRectMake(0, SCREEN_HEIGHT-45*SCREEN_WIDTH/320-64-34, SCREEN_WIDTH, 45*SCREEN_WIDTH/320);
        
    }else{
    
        self.AddBtn.frame=CGRectMake(0, SCREEN_HEIGHT-45*SCREEN_WIDTH/320-64, SCREEN_WIDTH, 45*SCREEN_WIDTH/320);
        
    }
    [self.AddBtn setTitle:self.AddBtnTitle forState:UIControlStateNormal];
    
    [self.AddBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    self.AddBtn.titleLabel.font=[UIFont systemFontOfSize:21];
    
    self.AddBtn.backgroundColor=TBColorProvideBtnbg;
    
    [self.view addSubview:self.AddBtn];
    
    [self.AddBtn addTarget:self action:@selector(addNewgoods) forControlEvents:UIControlEventTouchUpInside];
    //self.AddBtn.backgroundColor = [UIColor redColor];
    
}
//添加一个头部。


#pragma mark-新增事件
-(void)addNewgoods
{
    
    
}

#pragma mark-空白页点击事件
- (void)actionTapEmptyDataSetNodataView
{
    [self.homeTableView.mj_header beginRefreshing];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
